#ifndef PIDCONTROLER_H_
#define PIDCONTROLER_H_

#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/function.hpp>

class PIDControler
{	
	protected:
		
		boost::function<double (void)> m_ImportFunc;

		boost::function<void (double)>m_ExportFunc;

		// Operational variables
		double m_error;        // The proportional error
		double m_integral;     // The integral value
		double m_differential; // The differential value
		
		double m_dt;
		
	public:
		// Settable/readable parameters
		double m_gain_dif; // Gain for differential
		double m_gain_int; // Gain for integral
		double m_gain_error; // Gain for error

		int m_pidMax; // Maximum output value
		int m_pidMin; // Minimum output value

		double &m_target; // Target Rotation speed
		bool m_FirstTime;

		struct timeval lastTime, currentTime;
		int consigne;

		PIDControler(boost::function<double (void)> ImportFunc, boost::function<void (double)> ExportFunc, double &Consigne, double Min, double Max, double CoefP, double CoefI, double CoefD);
		~PIDControler();
		void Iteration();

};

#endif //PIDCONTROLER_H_
